var app = getApp()
// pages/order_list/order_list.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
      store:'',
      request_num:0,
      show:0,
      is_show_time:1,
      page:1,
      keywords:''
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  //店铺默认排名
  onLoad: function (options) {
    var that = this
    if (options.content){
      var keywords = options.content
    }else{
      var keywords = ''
    }
     
    wx.request({
      url: app.configData.shop.api_url + '/index.php?ctl=Shop_Index&met=index&typ=json&ua=wap',
      method: 'GET',
      data: {
        keywords: keywords
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        var page = Number(res.data.data.page + 1)
        that.setData({
          is_show_time: 0,
          store: res.data.data.items,
          keywords: keywords,
          page:page
        })
      }
    })
  },

  //搜索
  search: function () {
    wx.navigateTo({
      url: '../search/search'
    })
  },
  /**
  * 页面上拉触底事件的处理函数
  */
  onReachBottom: function () {
    
    var that = this
    if (that.data.request_num==1){
      return false
    }
    wx.request({
      url: app.configData.shop.api_url + '/index.php?ctl=Shop_Index&met=index&typ=json&ua=wap&rows=10',
      method: 'GET',
      data: {
        keywords: that.data.keywords,
        page: that.data.page
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data.data.items.length > 0) {
          var arr = that.data.store
          for (var z in res.data.data.items) {
            arr.push(res.data.data.items[z])
          }
          var page = Number(that.data.page + 1)
          that.setData({
            store: arr,
            page: page
          })
        } else {
          that.setData({
            request_num: 1
          })
        }
      }
    })
  },
  bindhref: function (e) {
    app.goTop()
    this.setData({
      show: 0
    })
  },
  //一键到顶
  onPageScroll: function (e) {
    // 获取滚动条当前位置
    var that = this
    wx.getSystemInfo({
      success: function (res) {
       
        if (e.scrollTop + res.windowHeight > res.windowHeight) {
          that.setData({
            show: 1
          })
        } else {
          that.setData({
            show: 0
          })
        }
      },
    })
  },
  //下拉刷新
  onPullDownRefresh: function () {
    var that = this
    wx.showToast({
      title: '加载中',//提示信息
      icon: 'loading',//成功显示图标
      duration: 2000//时间
    })
    wx.stopPullDownRefresh()
    that.onLoad()
  },
})